package com.ruoyi.resitExam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.resitExam.domain.SysResitExam;
import com.ruoyi.resitExam.service.ISysResitExamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生补考Controller
 * 
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/resitExam/resitExam")
public class SysResitExamController extends BaseController {
    @Autowired
    private ISysResitExamService sysResitExamService;

    /**
     * 查询学生补考列表
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysResitExam sysResitExam) {
        startPage();
        List<SysResitExam> list = sysResitExamService.selectSysResitExamList(sysResitExam);
        return getDataTable(list);
    }

    /**
     * 导出学生补考列表
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:export')")
    @Log(title = "学生补考", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysResitExam sysResitExam) {
        List<SysResitExam> list = sysResitExamService.selectSysResitExamList(sysResitExam);
        ExcelUtil<SysResitExam> util = new ExcelUtil<SysResitExam>(SysResitExam.class);
        util.exportExcel(response, list, "学生补考数据");
    }

    /**
     * 获取学生补考详细信息
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:query')")
    @GetMapping(value = "/{resitId}")
    public AjaxResult getInfo(@PathVariable("resitId") Integer resitId) {
        return success(sysResitExamService.selectSysResitExamByResitId(resitId));
    }

    /**
     * 新增学生补考
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:add')")
    @Log(title = "学生补考", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysResitExam sysResitExam) {
        return toAjax(sysResitExamService.insertSysResitExam(sysResitExam));
    }

    /**
     * 修改学生补考
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:edit')")
    @Log(title = "学生补考", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysResitExam sysResitExam) {
        return toAjax(sysResitExamService.updateSysResitExam(sysResitExam));
    }

    /**
     * 删除学生补考
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:remove')")
    @Log(title = "学生补考", businessType = BusinessType.DELETE)
    @DeleteMapping("/{resitIds}")
    public AjaxResult remove(@PathVariable Integer[] resitIds) {
        return toAjax(sysResitExamService.deleteSysResitExamByResitIds(resitIds));
    }

    /**
     * 检查成绩是否已申请补考
     */
    @PreAuthorize("@ss.hasPermi('resitExam:resitExam:query')")
    @GetMapping("/check")
    public AjaxResult checkExist(SysResitExam sysResitExam) {
        return success(sysResitExamService.checkResitExamExists(sysResitExam));
    }
}
